package com.example.esc_im_client.ui.menu;

import static java.security.AccessController.getContext;

import android.os.Bundle;
import android.view.View;


import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.example.esc_im_client.R;
import com.example.esc_im_client.ui.friend.CustomAdapter;

import java.util.Arrays;

/**
 * @ClassName: MenuActivity
 * @Description:
 * @Author: 墨渍
 * @Date: 2024/2/27 14:35
 **/
public class MenuActivity extends AppCompatActivity {

    private ListView listViewLeft;
    private ListView listViewRight;

    private Object[][] rightData = {
            {"右侧菜单1-1", R.drawable.ic_dashboard_black_24dp},
            {"右侧菜单1-2", R.drawable.ic_dashboard_black_24dp},
            {"右侧菜单1-3", R.drawable.ic_dashboard_black_24dp},
            {"右侧菜单2-1", R.drawable.ic_dashboard_black_24dp},
            {"右侧菜单2-2", R.drawable.ic_dashboard_black_24dp},
            {"右侧菜单2-3", R.drawable.ic_dashboard_black_24dp},
            {"右侧菜单3-1", R.drawable.ic_dashboard_black_24dp},
            {"右侧菜单3-2", R.drawable.ic_dashboard_black_24dp},
            {"右侧菜单3-3", R.drawable.ic_dashboard_black_24dp}
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);


        listViewLeft = findViewById(R.id.listview_left);
        listViewRight = findViewById(R.id.listview_right);

        // 左侧菜单数据
        String[] leftData = {"左侧菜单1", "左侧菜单2", "左侧菜单3"};

        // 左侧菜单适配器
        ArrayAdapter<String> leftAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, leftData);
        listViewLeft.setAdapter(leftAdapter);

        // 右侧菜单适配器
        CustomAdapter rightAdapter = new CustomAdapter(this, R.layout.custom_list_item, Arrays.asList(rightData));
        listViewRight.setAdapter(rightAdapter);

        // 添加带图片的右侧菜单项
//        for (Object[] item : rightData) {
//            rightAdapter.add(item);
//        }

        // 左侧菜单点击事件
        listViewLeft.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // 更新右侧菜单数据
                rightAdapter.clear();
                for (Object[] item : rightData) {
                    if (((String) item[0]).startsWith("右侧菜单" + (position + 1))) {
                        rightAdapter.add(item);
                    }
                }
            }
        });

        // 右侧菜单点击事件
        listViewRight.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // 处理右侧菜单项点击事件
                Object[] item = (Object[]) parent.getItemAtPosition(position);
                String itemName = (String) item[0];
                System.out.println("点击了" + itemName);
            }
        });
    }
}
